﻿using System;

namespace MovieBrowser.Model
{
    public partial class Person
    {
        public Person Clone(Person personInfo)
        {
            Birthday = personInfo.Birthday;
            Deathday = personInfo.Deathday;
            Height = personInfo.Height;
            Highlight = personInfo.Highlight;
            Profession = personInfo.Profession;
            Country = personInfo.Country;
            Birthplace = personInfo.Birthplace;
            Fullname = personInfo.Fullname;
            Bio = personInfo.Bio;

            return this;
        }

        public long WorksCount
        {
            get
            {
                return WorksAsActor + WorksAsDirector + WorksAsWriter;
            }

        }

        public string Age
        {
            get
            {
                if (Birthday == null)
                    return "";
                else
                {
                    DateTime now;
                    if (Deathday == null)
                    {
                        now = DateTime.Today;
                    }
                    else
                    {
                        now = Deathday.Value;
                    }
                    int age = now.Year - Birthday.Value.Year;
                    if (Birthday.Value > now.AddYears(-age)) age--;
                    return "" + age;
                }
            }
        }

        public bool Favorite { get; set; }

        public string AgeAt(long year)
        {
            if (Birthday == null)
                return "";
            else
            {
                DateTime now = new DateTime((int)year, 1, 1);
                int age = now.Year - Birthday.Value.Year;
                if (Birthday.Value > now.AddYears(-age)) age--;
                return "" + age;
            }
        }

        public override bool Equals(System.Object obj)
        {
            // If parameter is null return false.
            if (obj == null)
            {
                return false;
            }

            // If parameter cannot be cast to Point return false.
            Person p = obj as Person;
            if ((System.Object)p == null)
            {
                return false;
            }

            // Return true if the fields match:
            return (Id == p.Id);
        }

    }
}
